package sauvaget;


import java.util.ArrayList;

public class Image {
	
	//	private List<Color> colors;
	private ArrayList<Color> sectorY;
	private ArrayList<Color> sectorO;
	private ArrayList<Color> sectorR;
	private ArrayList<Color> sectorV;
	private ArrayList<Color> sectorB;
	private ArrayList<Color> sectorG;	
	
	/**
	 * Define a imagem como setores de cor
	 */
	public Image(ArrayList<Color> sectorY, ArrayList<Color> sectorO, ArrayList<Color> sectorR,
			ArrayList<Color> sectorV, ArrayList<Color> sectorB, ArrayList<Color> sectorG) {
		 sectorY = this.sectorY;
		 sectorO = this.sectorO;
		 sectorR = this.sectorR;
		 sectorV = this.sectorV;
		 sectorB = this.sectorB;
		 sectorG = this.sectorG;
	}
	
	public Image(ArrayList<Color> sectorY, ArrayList<Color> sectorV, ArrayList<Color> sectorG) {
		sectorY = this.sectorY;
		sectorV = this.sectorV;
		sectorG = this.sectorG;
	}
	
	public Image(ArrayList<Color> sectorB, ArrayList<Color> sectorO) {
		this.sectorB = sectorB;
		this.sectorO = sectorO;	
	}
	
/*	public Image(ArrayList<Color> sectorG, ArrayList<Color> sectorR) {
		this.sectorG = sectorG;
		this.sectorR = sectorR;
	}*/
	
	public Image() {}

	/**
	 * 
	 * @return Colors of the image
	 */
	public ArrayList<Color> getColors() {
		ArrayList<Color> colors = new ArrayList<Color>();
		colors.addAll(sectorY);
		colors.addAll(sectorV);
		colors.addAll(sectorR);
		colors.addAll(sectorG);
		colors.addAll(sectorB);
		colors.addAll(sectorO);
		
		return colors;
	}
	
	/**
	 * Adiciona as cores da imagem em seus setores especificos
	 * @param c
	 */
	public void crateImage(Color c) {
		if (c != null) {
			if (c.getColorName() == EnumColor.YELLOW) {
				sectorY.add(c); 
			} else if (c.getColorName() == EnumColor.VIOLET) {
				sectorV.add(c);
			} else if (c.getColorName() == EnumColor.RED) {
				sectorR.add(c);
			} else if (c.getColorName() == EnumColor.ORANGE) {
				sectorO.add(c);
			} else if (c.getColorName() == EnumColor.GREEN) {
				sectorG.add(c);
			} else {
				sectorB.add(c);
			}
		}
	}
	
	/**
	 * Calcula o tamanho do setor (numero de pixels do setor)
	 * @param sector
	 */
	public int calculateSectorSize(ArrayList<Color> sector) {
		int sizeSector = 0;
		for (int i = 0; i <= sector.size(); i++) { 
			sizeSector += sector.get(i).getNumPixels();
		}
		return sizeSector;
	}
	
	public int getSizeY() {
		int sizeY;
		sizeY = calculateSectorSize(sectorY);
		if (sizeY == 0) {
			sizeY = 1;
		}
		return sizeY;
	}
	
	public int getSizeV() {
		int sizeV;
		sizeV = calculateSectorSize(sectorV);
		if (sizeV == 0) {
			sizeV = 1;
		}
		return sizeV;
	}
	
	public int getSizeR() {
		int sizeR;
		sizeR = calculateSectorSize(sectorR);
		if (sizeR == 0) {
			sizeR = 1;
		}
		return sizeR;
	}
	
	public int getSizeO() {
		int sizeO;
		sizeO = calculateSectorSize(sectorO);
		if (sizeO == 0) {
			sizeO = 1;
		}
		return sizeO;
	}
	
	public int getSizeG() {
		int sizeG;
		sizeG = calculateSectorSize(sectorG);
		if (sizeG == 0) {
			sizeG = 1;
		}
		return sizeG;
	}
	
	public int getSizeB() {
		int sizeB;
		sizeB = calculateSectorSize(sectorB);
		if (sizeB == 0) {
			sizeB = 1;
		}
		return sizeB;
	}
	
	
	/**
	 * 
	 * @param toRemove cor a ser removida	
	 * @param newColor nova cor
	 */
	public void setColors(Color toRemove, Color newColor) {

		if (toRemove.getColorName() == EnumColor.BLUE) {
			if (sectorB.contains(toRemove)) {
				toRemove = newColor;
			}
		} 
		if (toRemove.getColorName() == EnumColor.GREEN) {
			if (sectorG.contains(toRemove)) {
				toRemove = newColor;
			}
		}
		if (toRemove.getColorName() == EnumColor.ORANGE) {
			if (sectorO.contains(toRemove)) {
				toRemove = newColor;
			}
		}
		if (toRemove.getColorName() == EnumColor.RED) {
			if (sectorR.contains(toRemove)) {
				toRemove = newColor;
			}
		}
		if (toRemove.getColorName() == EnumColor.VIOLET) {
			if (sectorV.contains(toRemove)) {
				toRemove = newColor;
			}
		}
		if (toRemove.getColorName() == EnumColor.YELLOW) {
			if (sectorY.contains(toRemove)) {
				toRemove = newColor;
			}
		}
	}
	
	/**
	 * 
	 * @param toRemove Cor a ser removida
	 */
	public void removeColor(Color toRemove) {
		if (sectorB.contains(toRemove)) {
			sectorB.remove(toRemove);
		} else if (sectorG.contains(toRemove)) {
			sectorG.remove(toRemove);
		} else if (sectorO.contains(toRemove)) {
			sectorO.remove(toRemove);
		} else if (sectorR.contains(toRemove)) {
			sectorR.remove(toRemove);
		} else if (sectorV.contains(toRemove)) {
			sectorV.remove(toRemove);
		} else if (sectorY.contains(toRemove)) {
			sectorY.remove(toRemove);
		} else {
			System.out.println("Try again");
		}
	}
	         
	public ArrayList<Color> getSetorY () {
		return sectorY;
	}
	
	public ArrayList<Color> getSetorV () {
		return sectorV;
	}
	
	public ArrayList<Color> getSetorR () {
		return sectorR;
	}
	
	public ArrayList<Color> getSetorO () {
		return sectorO;
	}
	
	public ArrayList<Color> getSetorG () {
		return sectorG;
	}
	
	public ArrayList<Color> getSetorB () {
		return sectorB;
	}
}
